﻿using Caliburn.Micro;
using System.Xml.Linq;

namespace SunXmlEditor
{
  public class SunXAttribute : PropertyChangedBase
  {
    public SunXAttribute(XElement xe, XAttribute xa)
    {
      _Element = xe;
      _Attribute = xa;
    }

    private readonly XElement _Element;
    private readonly XAttribute _Attribute;

    /// <summary>
    /// 特性名
    /// </summary>
    public string AttributeName => _Attribute.Name?.ToString();

    /// <summary>
    /// 绑定通知，特性值
    /// </summary>
    public string AttributeValue
    {
      get { return _Attribute.Value; }
      set
      {
        if (_Attribute.Value == value) { return; }
        _Attribute.Value = value;
        NotifyOfPropertyChange(nameof(AttributeValue));
      }
    }

    /// <summary>
    /// 从数据源中删除本节点特性信息。
    /// </summary>
    internal void Delete()
    {
      _Attribute.Remove();
    }
  }
}